
import { _decorator, director, instantiate, Node, Prefab } from 'cc';
import { RenderManager } from '../Base/RenderManager';
import { SCENE_ENUM } from '../Enum';
import DataManager from '../Runtime/DataManager';
const { ccclass, property } = _decorator;

@ccclass('SceneManager')
export class SceneManager extends RenderManager {

    @property(Node)
    items: Node = null;

    @property(Prefab)
    inventoryPrefab: Prefab = null;

    @property(Prefab)
    menuPrefab: Prefab = null;

    type: SCENE_ENUM;
    start() {
        super.start();
        // director.preloadScene(SCENE_ENUM.H1);
        // director.preloadScene(SCENE_ENUM.H2);
        // director.preloadScene(SCENE_ENUM.H3);
        // director.preloadScene(SCENE_ENUM.H4);

        if (this.inventoryPrefab) {
            const inventoryNode = instantiate(this.inventoryPrefab);
            this.node.addChild(inventoryNode);
        }
        if (this.menuPrefab) {
            const menu = instantiate(this.menuPrefab);
            this.node.addChild(menu);
        }
    }
    changeScene(event, customEventData) {
        DataManager.Instance.curScene = customEventData as SCENE_ENUM;
    }
    render() {
        if (this.type === DataManager.Instance.curScene) {
            return;
        }
        director.loadScene(DataManager.Instance.curScene);
    }
}

